<%@ page import="id.co.gomobile.assessment.User" %>

<%@page import="id.co.gomobile.assessment.Test"%>
<%@page import="java.math.MathContext"%>
<%@page import="org.joda.time.Period"%><html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <title>List of Assignments</title>
    </head>
    <body>
    <g:render template="/shared/navigation" />

    <div id="body">
    
    <div id="body">
    <h1>${testInstance ? "Assignments of " + testInstance.name : "Please Select Test"}</h1>
    
    <g:if test="${flash.message}">
        <div class="message">${flash.message}</div>
    </g:if>
    
    <g:form action="ofTest" method="post" >
    
    <div class="form">
    
    <fieldset>        
        <h3>Select Test</h3>

        <label for="name" class="required">Test :</label>
        <div class="value">
            <g:select name="id" from="${Test.list()}" optionKey="id" optionValue="name" noSelection="${['-1': '-']}" value="${testInstance?.id}" />
        </div>

        <br/>
        
        <label for="name" class="required">Finished Only :</label>
        <div class="value">
            <g:checkBox name="finishedOnly" value="${params.finishedOnly}" />
        </div>

        <br/>
        
        <label for="name" class="required">Display :</label>
        <div class="value">
            <g:select name="max" from="${[10, 50, 100]}" value="${params.max}" />
        </div>


        <br/>
        <br/>
        
        <div class="buttons">
            <span class="button"><g:submitButton name="display" class="show" value="${message(code: 'default.button.display.label', default: 'Display')}" /></span>
        </div>
    </fieldset>
    
    </div>
    
    </g:form>
    
    <br/>
    
    <fieldset>

    <g:if test="${assignmentInstanceList}">    
    
    <div class="list">
    <table>
        <col width="50" />
        <col />
        <col width="175" />
        <col width="175" />
        <col width="150" />
        <col width="150" />
        <thead>
            <tr>
                <g:sortableColumn property="id" params="${params}" title="${message(code: 'assignment.id.label', default: 'Id')}" />
                <th title="User">User</th>
                <g:sortableColumn property="endTime" params="${params}" title="${message(code: 'assignment.endTime.label', default: 'End Time')}" />
                <th title="Time Taken">Time Taken</th>
                <g:sortableColumn property="total" params="${params}" title="${message(code: 'assignment.total.label', default: 'Total Point')}" />
                <th title="Action">Action</th>
            </tr>
        </thead>
        <tbody>
        <g:each in="${assignmentInstanceList}" status="i" var="assignmentInstance">
            <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                <td>${fieldValue(bean: assignmentInstance, field: "id")}</td>
                <td><g:link controller="user" action="show" id="${assignmentInstance?.user?.id}">${assignmentInstance?.user.profile.fullname}</g:link></td>
                <td><g:formatDate date="${assignmentInstance?.endTime}" type="datetime" style="MEDIUM" timeStyle="MEDIUM"/></td>
                <td align="center">
                    <% Period period = new Period(assignmentInstance?.startTime.time, assignmentInstance?.endTime.time) %>
                    ${period.getHours()}:${period.getMinutes()}:${period.getSeconds()}
                </td>
                <td align="center"><strong>${assignmentInstance?.total.asType(int)} of ${assignmentInstance?.items?.size()} (${(assignmentInstance?.items?.size() > 0 ? ((assignmentInstance?.total.asType(int) / assignmentInstance?.items?.size()) * 100) : 0).round(new java.math.MathContext(4))}%)</strong></td>
                <td style="text-align: center">
                    <g:form action="show" id="${assignmentInstance?.id}" style="display: inline">
                        <input type="image" src="${resource(dir:'images/skin', file:'database_table.png')}" alt="Show" />
                    </g:form>
                    &nbsp;
                    <g:form action="delete" id="${assignmentInstance?.id}" style="display: inline">
                        <input type="image" src="${resource(dir:'images/skin', file:'database_delete.png')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" alt="Delete" />
                    </g:form>
                </td>
            </tr>
        </g:each>
        </tbody>
    </table>
    </div>
    
    </g:if>
    <g:else>
    <fieldset>
    Nothing to display
    </fieldset>
    </g:else>
    
    </fieldset>
    
    </div>

    </body>
</html>